package Exists;

import java.util.Comparator;
import java.util.Iterator;
import java.util.TreeSet;

public class TreeSetTest {

    public static void main(String[] args) {
        TreeSet<Person> res = new TreeSet<>();


        res.add(new Person("张三山", 183, 140));
        res.add(new Person("李四", 180, 140));
        res.add(new Person("王二", 178, 138));
        res.add(new Person("小花", 165, 110));


        Iterator<Person> iterator = res.iterator();
        while (iterator.hasNext()) {


            System.out.println(iterator.next());
        }
        Comparablt();

    }

    private static void Comparablt() {
        TreeSet<Person> res = new TreeSet<>(new Comparator<Person>() {
            @Override
            public int compare(Person o1, Person o2) {
                int b = o1.getHigth() - o2.getHigth();

                return  b == 0 ? o1.getWeight() - o2.getWeight() : b;


            }
        });


        res.add(new Person("张三山", 183, 140));
        res.add(new Person("李四", 180, 140));
        res.add(new Person("王二", 178, 138));
        res.add(new Person("小花", 165, 110));


        Iterator<Person> iterator = res.iterator();
        while (iterator.hasNext()) {


            System.out.println(iterator.next());
        }


    }
}
